import request from '@/utils/request'

/**
 * 获取-所有频道列表
 * @returns
 */
export const getChannelsList = () => {
  return request({
    url: '/v1_0/channels'
  })
}

// 登录接口
export const loginAPI = (data) => {
  return request({
    url: '/v1_0/authorizations',
    method: 'POST',
    data
  })
}

/**
 * 获取-用户已选频道
 * @returns Promise对象
 */
export const getUserList = () => {
  return request({
    url: '/v1_0/user/channels'
  })
}

/**
 * 获取-文章列表
 * @param {*} params
 * @returns
 */
export const getArticlesList = (params) => {
  return request({
    url: '/v1_0/articles',
    params
  })
}
/**
 * 反馈 - 不感兴趣
 * @param {*} data 文章id
 * @returns Promise对象
 */
export const dislikesAPI = ({ id }) => {
  return request({
    url: '/v1_0/article/dislikes',
    method: 'post',
    data: {
      target: id
    }
  })
}

/**
 * 反馈 - 举报文章
 * @param {*} param
 * @returns
 */
export const reportsAPI = ({ artID, type, remark }) => {
  const dataObj = {
    target: artID,
    type
  }
  if (type === 0) {
    dataObj.remark = remark
  }
  return request({
    url: '/v1_0/article/reports',
    method: 'post',
    data: dataObj
  })
}
/**
 * 更新频道列表
 * @param {*} channels
 * @returns
 */
export const updateListAPI = ({ channels }) => {
  return request({
    url: '/v1_0/user/channels',
    method: 'put',
    data: {
      channels
    }
  })
}

/**
 * 获取-搜索联想建议
 * @param {*} keyWord
 * @returns
 */
export const getSuggestionAPI = ({ keyWord }) => {
  return request({
    url: '/v1_0/suggestion',
    params: {
      q: keyWord
    }
  })
}
/**
 * 获取-搜索结果
 * @param {*} data
 * @returns
 */
export const getSearchListAPI = (data) => {
  return request({
    url: '/v1_0/search',
    params: data
  })
}

/**
 * 获取-文章详情
 * @param {*} param0
 * @returns
 */
export const getArticlesListAPI = ({ id }) => {
  return request({
    url: `/v1_0/articles/${id}`
  })
}

/**
 * 文章-关注作者
 * @param {*} param0
 * @returns
 */
export const followingsAPI = ({ target }) => {
  return request({
    url: '/v1_0/user/followings',
    method: 'post',
    data: {
      target
    }
  })
}

/**
 * 文章-取关作者
 * @param {*} param0
 * @returns
 */
export const unFollowingsAPI = ({ tag }) => {
  return request({
    url: `/v1_0/user/followings/${tag}`,
    method: 'DELETE'
  })
}

/**
 * 文章-点赞
 * @param {*} param0
 * @returns
 */
export const likingsAPI = ({ target }) => {
  return request({
    url: '/v1_0/article/likings',
    method: 'post',
    data: {
      target
    }
  })
}

/**
 * 文章-取消点赞
 * @param {*} param0
 * @returns
 */
export const unLikingsAPI = ({ tag }) => {
  return request({
    url: `/v1_0/article/likings/${tag}`,
    method: 'DELETE'
  })
}

/**
 * 获取-文章评论列表
 * @param {*} param0
 * @returns
 */
export const getCommentsAPI = ({ artId, offset = null, limit = 10 }) => {
  return request({
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source: artId,
      offset,
      limit
    }
  })
}

/**
 * 评论-点赞
 * @param {*} param0
 * @returns
 */
export const likingLoveAPI = ({ target }) => {
  return request({
    url: '/v1_0/comment/likings',
    method: 'post',
    data: {
      target
    }
  })
}

/**
 * 评论-取消点赞
 * @param {*} param0
 * @returns
 */
export const unLikingLoveAPI = ({ tag }) => {
  return request({
    url: `/v1_0/comment/likings/${tag}`,
    method: 'DELETE'
  })
}

/**
 * 增加-文章评论
 * @param {*} param0
 * @returns
 */
export const addCommentsAPI = ({ artId, content }) => {
  return request({
    url: '/v1_0/comments',
    method: 'post',
    data: {
      target: artId,
      content
    }
  })
}

/**
 * 获取-用户基本资料
 */
export const getUserInfoAPI = () => {
  return request({
    url: '/v1_0/user'
  })
}

/**
 * 获取-用户个人简介
 * @returns
 */
export const getUserProfileAPI = () => {
  return request({
    url: '/v1_0/user/profile'
  })
}

/**
 * 更新-用户头像
 * @param {*} param0
 * @returns
 */
export const updatePhotoAPI = (formObj) => {
  return request({
    url: '/v1_0/user/photo',
    method: 'PATCH',
    data: formObj
  })
}

export const updeUserProfileAPI = ({ name, birthday }) => {
  return request({
    url: '/v1_0/user/profile',
    method: 'PATCH',
    data: {
      name,
      birthday
    }
  })
}
